<?php

namespace app\xwam\controller;

/**
 * 网站设置 控制器
 *
 * @version 1.0 2015-10-20 SoChishun(14507247@qq.com) Added.
 * @version 1.1 2016-7-6 SoChishun SiteConfig 重构为 SiteConf
 * @version 1.2 2017-3-23 SiteConf重命名为Settings
 */
class Settings extends AppbaseController {

    // 2016-4-21
    public function base() {
        $mSite = new \app\xwam\model\WebsiteConfModel();
        $data = $mSite->findSite(1, '');
        $this->assign('data', $data);
        $this->assign('tabs', $this->getTabs());
        return view();
    }

    // 2017-3-23
    public function seo() {
        $mSite = new \app\xwam\model\WebsiteConfModel();
        $data = $mSite->findSite(1, '');
        $this->assign('data', $data);
        $this->assign('tabs', $this->getTabs());
        return view();
    }

    // 2017-3-23
    public function lang() {
        $mSite = new \app\xwam\model\WebsiteConfModel();
        $data = $mSite->findSite(1, '');
        $this->assign('data', $data);
        $this->assign('tabs', $this->getTabs());
        return view();
    }

    // 2017-3-23
    public function db() {
        $mSite = new \app\xwam\model\WebsiteConfModel();
        $data = $mSite->findSite(1, '');
        $this->assign('data', $data);
        $this->assign('tabs', $this->getTabs());
        return view();
    }

    // 2017-3-23
    public function content() {
        $mSite = new \app\xwam\model\WebsiteConfModel();
        $data = $mSite->findSite(1, '');
        $this->assign('data', $data);
        $this->assign('tabs', $this->getTabs());
        return view();
    }

    // 2017-3-23
    public function admin() {
        $mSite = new \app\xwam\model\WebsiteConfModel();
        $data = $mSite->findSite(1, '');
        $this->assign('data', $data);
        $this->assign('tabs', $this->getTabs());
        return view();
    }
    /**
     * 保存表单数据
     * @version 2017-3-23 added.
     * @version 2018-1-29 重构.
     */
    public function editSave() {
        $tab=input('tab');
        if(!$tab){
            $this->error('未设置分组标识!');
        }
        $mSite = new \app\xwam\model\WebsiteConfModel();
        $result = $mSite->saveSite();
        if($result['status']){
            $this->success('保存成功',$tab,'',2);
        }else{
            $this->error($result['info']);
        }
    }

    // 2017-3-23
    protected function getTabs($name = '') {
        if (!$name) {
            $name = \think\Request::instance()->action();
        }
        $data = array(
            'base' => array('title' => '基本信息', 'url' => 'base', 'active' => ''),
            'seo' => array('title' => 'SEO优化', 'url' => 'seo', 'active' => ''),
            'lang' => array('title' => '多语言设置', 'url' => 'lang', 'active' => ''),
            'db' => array('title' => '数据库设置', 'url' => 'db', 'active' => ''),
            'admin' => array('title' => '管理员设置', 'url' => 'admin', 'active' => ''),
            'content' => array('title' => '内容设置', 'url' => 'content', 'active' => ''),
        );
        if (array_key_exists($name, $data)) {
            $data[$name]['active'] = 'active';
        }
        return $data;
    }

}
